﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using InfoSource.Utilities;
using InfoSource.Models;
using InfoSource.Models.Views;
using InfoSource.Data;
using InfoSource.Models.objects;

namespace InfoSource.Controllers
{
	[HandleError]
	public class APIController : BaseController
	{
		
		/*----------------------------------------------------------*/
		public JsonResult GetCoordinatesFromKMLFile(string zipcode)
		{
			List<List<LatLong>> latLong = Helpers.GetCoordinatesFromKMLFile(zipcode);														


			return Json(latLong, JsonRequestBehavior.AllowGet);

			//foreach (XElement placemark in placemarks)
			//{
			//    string name = placemark.Element("name").Value;

			//    if (!nameCoord.ContainsKey(name))
			//    {
			//        nameCoord[name] = new List<string>();
			//    }

			//    nameCoord[name].AddRange(placemark.Descendants("coordinates").Select(co => co.Value));
			//}
		}

		/*----------------------------------------------------------*/
		public ActionResult GetSeniorAndSpecialistForZipCode(int zipcode)
		{	
			var techs = TechnicianRequests.GetSeniorAndSpecialistForZipcode(zipcode);

			return Json(techs, JsonRequestBehavior.AllowGet);
		}

		/*----------------------------------------------------------*/
		public ActionResult GetContractorDetails(string code)
		{
			var details = ContractorRequests.GetContractorDetails(code);

			return Json(details, JsonRequestBehavior.AllowGet);
		}

	}
}
